<?php

class Campaign_model extends CI_Model{
	
	
	function __construct(){

				         		   
        }
		function get_campaign_options($campaign_uid){
	$sql="SELECT * FROM mw_campaign_option,mw_campaign where mw_campaign_option.campaign_id = mw_campaign.campaign_id AND mw_campaign.campaign_uid = '".$campaign_uid."'";
	$campaign=	$this->db->query($sql)->row_array();
		return $campaign;
		}

	function getall_lists()
	{
		 $this->db->from('mw_list');
		 $this->db->order_by("list_id", "asc"); 
	   	 return $this->db->get();
	}
	function get_list_subscribers()
	{
		$sql = 'SELECT mw_list.list_id,mw_list.name,mw_list.date_added,mw_list.last_updated from mw_list ';
		$sql = $sql.' where mw_list.user_id = '.$this->session->userdata('user_id');
		$lists=	$this->db->query($sql)->result();
		$subscribers_list=array();
		$new_list=array();
		foreach($lists as $list)
		{
		$sql = "SELECT COUNT(mw_list_subscriber.subscriber_id) as subscriber_count from mw_list_subscriber WHERE mw_list_subscriber.list_id = ".$list->list_id;
		$subscriber_count = $this->db->query($sql)->result();
		$new_list['list'] = $list;
		$new_list['subscriber_count'] = $subscriber_count;		
		array_push($subscribers_list,$new_list);			
		}
		return $subscribers_list;

	}
	
	function get_list_defaults($list_id)
	{
	$sql="SELECT  mw_list.list_id,mw_list.name,from_name,from_email,reply_to,subject FROM mw_list_default,mw_list where mw_list.list_id =    mw_list_default.list_id AND mw_list.list_id = ".$list_id;
		$lists=	$this->db->query($sql)->row_array();
		return $lists;
	}
	
	
	
}
